import { AfterContentInit, AfterViewInit, Component, ContentChild, ElementRef, TemplateRef } from '@angular/core';
import { SunshineNgContentComponent } from "./sunshine-ng-content.component";
import { CommonModule, NgIf, NgTemplateOutlet } from '@angular/common';

@Component({
  selector: 'app-sunshine-ng-content-parent',
  standalone: true,
  imports: [SunshineNgContentComponent, NgTemplateOutlet, CommonModule],
  templateUrl: './sunshine-ng-content-parent.component.html',
  styleUrls: []
})
export class SunshineNgContentParentComponent implements AfterContentInit {
  context: string = '这是一个传入content的内用';
  idContent: string = 'id content';

  doClick() {
    console.log(this.id)
    this.idContent = "123123";
    alert(this.idContent),
      this.ngAfterContentInit();
  }
  @ContentChild('.head1', { static: false }) private headEle!: ElementRef<HTMLSpanElement>
  @ContentChild('#id', { static: false }) private id!: ElementRef<HTMLSpanElement>

  // 通过标签获取子元素
  @ContentChild('.input-number', { static: false }) private headEle3!: ElementRef<HTMLSpanElement>
  @ContentChild('other1', { static: false }) private headEle2!: ElementRef<HTMLDivElement>

  ngAfterContentInit(): void {
    console.log(this.headEle)
    console.log(this.headEle2)
    console.log(this.headEle3)
  }
}
